package com.momo.hotel.controller;


import com.momo.hotel.dao.pojo.ext.TbRoomList;
import com.momo.hotel.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;


@Controller
public class RoomController {

    @Autowired
    RoomService roomService;

    /**
     * 获取房间信息，并setAttribute
     * @return
     */

    @RequestMapping("/selectRoomById")
    public String selectRoomById(HttpServletRequest request) {
        String id = request.getParameter("id");
        TbRoomList tbRoomList = roomService.selectRoomById(Integer.parseInt(id));
        request.getSession().setAttribute("tbRoomDetail",tbRoomList);
        return "rooms-detail";
    }

    /**
     * 根据getAttribute获取房间详情
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("selectRoomById1")
    public TbRoomList selectRoomById1(HttpServletRequest request) {
        TbRoomList tbRoomDetail = (TbRoomList) request.getSession().getAttribute("tbRoomDetail");
        return tbRoomDetail;
    }





}
